package com.gljx.web.service.impl;

import com.gljx.web.Entity.SubjectThreeRegentry;
import com.gljx.web.Entity.User;
import com.gljx.web.dao.SubjectThreeRegentryMapper;
import com.gljx.web.service.CustomLogService;
import com.gljx.web.service.SubjectThreeRegentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class SubjectThreeRegentryServiceImpl implements SubjectThreeRegentryService {
	@Autowired
	private SubjectThreeRegentryMapper subjectThreeRegentryMapper;

	@Autowired
	private CustomLogService customLogService;
	@Override
	public List<SubjectThreeRegentry> selSubjectThreeRegentryByParentId(String fid, String studentName) {
		// TODO Auto-generated method stub
		return subjectThreeRegentryMapper.selSubjectThreeRegentryByParentId(fid, studentName);
	}

	@Override
	public SubjectThreeRegentry selSharCarThreeRegBySutid(String lcsjid, String studentid) {
		// TODO Auto-generated method stub
		return subjectThreeRegentryMapper.selSharCarThreeRegBySutid(lcsjid, studentid);
	}

	@Override
	public SubjectThreeRegentry selChangeCarThreeRegBySutid(String lcsjid, String studentid) {
		// TODO Auto-generated method stub
		List<SubjectThreeRegentry> subjectThreeRegentries = subjectThreeRegentryMapper.selChangeCarThreeRegBySutid(lcsjid, studentid);
		if (subjectThreeRegentries.size() >0) {
			return subjectThreeRegentries.get(0);
		}
		return null;

	}

	@Override
	public int deleteByParentId(String parentid, User user,String fbizdate,String fnumber) {
		// TODO Auto-generated method stub
		if(user !=null){
			//根据父类id查找子类信息
			List<SubjectThreeRegentry> subjectThreeRegentries=subjectThreeRegentryMapper.selSubjectThreeRegentryByParentId(parentid,null);
			for (int i = 0; i <subjectThreeRegentries.size() ; i++) {
				//添加学员的服务日志
				customLogService.addLog("考试管理",  "删除了学员:"+subjectThreeRegentries.get(i).getCfstudentno()+subjectThreeRegentries.get(i).getStudentName()+
						",科目三考试登记!车型:"+subjectThreeRegentries.get(i).getCfsqcx()+",教练:"+subjectThreeRegentries.get(i).getJlzname()+",考试日期:"+fbizdate+",单据编号:"+fnumber, subjectThreeRegentries.get(i).getCfstudentid(), user.getFid());
			}
		}
		return subjectThreeRegentryMapper.deleteByParentId(parentid);
	}

}
